package org.example.frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.example.model.*;

/**
 * @author lenovo
 */

public class SecondFrame extends JFrame{
    public SecondFrame(User user){
        //组件准备
        JButton userButton = new JButton("用户管理");
        JButton courseButton = new JButton("课程管理");
        JButton studentButton = new JButton("学生管理");
        JButton scoreButton = new JButton("成绩管理");
        JButton dataButton = new JButton("数据管理");
        JButton helpButton = new JButton("必看帮助");
        Box box1 = Box.createHorizontalBox();
        Box box2 = Box.createHorizontalBox();
        Box box = Box.createVerticalBox();
        JPanel panel = new JPanel();
        //注册监视器
        userButton.addActionListener((ActionEvent e)->{
            new UserFrame(user);
            dispose();
        });
        courseButton.addActionListener((ActionEvent e)->{
            new CourseFrame(user);
            dispose();
        });
        studentButton.addActionListener((ActionEvent e)->{
            new StudentFrame(user);
            dispose();
        });
        scoreButton.addActionListener((ActionEvent e)->{
            new ScoreFrame(user);
            dispose();
        });
        dataButton.addActionListener((ActionEvent e)->{
            new DataFrame(user);
            dispose();
        });
        helpButton.addActionListener((ActionEvent e)->{
            new HelpFrame(user);
            dispose();
        });
        //添加组件
        box1.add(userButton);
        box1.add(Box.createHorizontalStrut(5));
        box1.add(courseButton);
        box1.add(Box.createHorizontalStrut(5));
        box1.add(studentButton);
        box2.add(scoreButton);
        box2.add(Box.createHorizontalStrut(5));
        box2.add(dataButton);
        box2.add(Box.createHorizontalStrut(5));
        box2.add(helpButton);
        box.add(box1);
        box.add(Box.createVerticalStrut(5));
        box.add(box2);
        panel.add(box);
        add(new JLabel("当前用户用户名："+user.getUsername()),BorderLayout.NORTH);
        add(panel,BorderLayout.CENTER);
        //窗口设置
        setTitle("学生成绩管理");
        setSize(500,400);
        setLocationRelativeTo(null);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        validate();
    }
}
